<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" type="text/css" href="/easyui.css">
    <link rel="stylesheet" type="text/css" href="/icon.css">
    <link rel="stylesheet" type="text/css" href="/demo.css">
    <script src="/jquery.min.js"></script>
    <script src="/jquery.easyui.min.js"></script>
    <meta charset="UTF-8">
    <title>老师课程表</title>
</head>
<body>
<h2>老师列表：</h2>
<table id="teacher"></table>
<h2>所选课程如下：</h2>
<button id="button" value="分配">分配</button>
<table id="kecheng"></table>
<script type="text/javascript">
    $("#teacher").datagrid({
        url: "/TeacherKechengController/teacherData",
        singleSelect: true,
        toolbar: "#toolbar",
        rownumbers: "true",
        fitColumns: "true",
        pagination: "true",
        pageSize: 10,
        columns: [[
            {field: 'tid', title: '教师编号', width: 100},
            {field: 'tname', title: '姓名', width: 100},
            {field: 'tsex', title: '性别', width: 50}
        ]]
    });
    var tearCherKech = [];
    $("#kecheng").datagrid({
        url:'/TeacherKechengController/kechengDate',
        toolbar:'#toolbar',
        rownumber:'true',
        fitColumns:'true',
        pagination:"true",
        pageSize:10,
        columns:[[
            {field:'kid',title:'课程编号',with:100},
            {field:'kname',title:'课程名称',width:100}
        ]],
        onLoadSuccess:function(data){
            //var  i =0;
            $.each(data.rows,function(index,value){
                $.each(tearCherKech,function(j,v){
                    if(value.kid == v.kid){
                        $("#kecheng").datagrid('selectRow',index);
                    }
                });
               // i++;
            });
        }
    });
    var tid = "";
    $("#teacher").datagrid({
        onClickRow:function(rowIndex, rowData){
            tid = rowData.tid;
            $.post('/TeacherKechengController/teacherShowKecheng',{tid:rowData.tid},function (data) {
                tearCherKech = data;
                $("#kecheng").datagrid('reload');
            });
        }
    });
    var str = [];
    $("#button").click(function () {
//        获取表格中被选中的多行数据
        rows = $("#kecheng").datagrid('getSelections');
        $.each(rows,function (i,v) {
            str[i] = rows[i].kid;
        });

       $.post("/TeacherKechengController/allSelectedKecheng",{str:str,tid:tid});
    });


</script>
</body>
</html>